package logic;
import java.io.*;
import java.lang.Math;
import java.util.ArrayList;
public class GateBlock
{
	private ArrayList<GATE> gates;
	private int step;
	public GateBlock(int s)
	{
		gates=new ArrayList<GATE>();
		step=s;
	}
	public void addGates(GATE[]gates_array)
	{
		for(GATE gate:gates_array)
		{
			gates.add(gate);
		}
	}
	public void addGate(GATE g)
	{
		gates.add(g);
	}
	public void output()
	{
		System.out.println("");
		System.out.println("Block:"+step);
		for(GATE gate:gates)
		{
			gate.output();
		}
	}
	public void decompose1()
	{
		ArrayList<GATE> new_gates=new ArrayList<GATE>();
		for(GATE gate:gates)
		{
			if((!gate.isSingleQubitGate())|(GATELIB.isInLibrary(gate.getName())))
			 {
			  new_gates.add(gate);	 
			  continue;
			 }
			String seq=gate.decompose1();
			char[] qn=new char[1];
			for(int i=0;i<seq.length();i++)
			 {
				 qn[0]=seq.charAt(i);
				 GATE g=new GATE(new String(qn));
				 g.connectQubits(gate.getTargetQbit(),null);
				 new_gates.add(g);
			 }
		}
		gates=new_gates;
	}	
}

